import { createRouter, createWebHashHistory } from 'vue-router'
import index from '@/views/index.vue'

const routes = [
  {
    path: '/',
    name: 'index',
    component: index,
    meta: {
      title: "index",
      // showHeader: true,
      // showFooter: true,
      // showBack: true,
      // keepAlive: false
    }
  },
  {
    path: '/home',
    name: 'Home',
    component: () => import(/* webpackChunkName: "Home"，webpackPrefetch: true */ '@/views/home/home.vue'),
    meta: {
      title: "Home",
      showHeader: true,
      showFooter: true,
      keepAlive: true,
      level: 0, // 几级页面 0 1 2
      transition: 1 // 一级页面排序
    }
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import(/* webpackChunkName: "Login"，webpackPrefetch: true */ '@/views/login/login.vue'),
    meta: {
      title: "Login",
      showHeader: false,
      showFooter: false,
      keepAlive: false,
      level: 1, // 几级页面
    }
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior(to) {
      return { top: 0 }
    }
})


router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
